package com.doone.telmarket.action.admin;

import java.util.List;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import com.doone.telmarket.domain.ibator.ServiceClassify;
import com.doone.telmarket.service.ServiceClassifyOperation;
import com.opensymphony.xwork2.ActionSupport;

/**
 * @package com.doone.telmarket.admin.action
 * @author 甘雨波
 * @date 2009-09-15 15:32
 * @description 增值业务功能类别ACTION
 *
 */
public class ServiceClassifyAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	Logger log = Logger.getLogger(ServiceTypeAction.class);

	@Autowired
	private ServiceClassifyOperation remoteServiceClassifyOperation;

	private String serviceClassifyId;

	private String serviceClassifyName;

	private List<ServiceClassify> serviceClassify;

	private String page;

	/**
	 * @description 保存增值业务功能类别
	 * @author 甘雨波
	 * @date 2009-9-14 13:41
	 * @return
	 */
	@Action(value = "saveServiceClassify", results = { @Result(name = "success", location = "/admin/success.jsp"),
			@Result(name = "error", location = "/admin/error.jsp") })
	public String saveServiceType() {
		try {
			//log.info(">>>>>>>>>>"+serviceClassifyName);
			ServiceClassify s = new ServiceClassify();
			s.setServiceClassifyName(serviceClassifyName);
			int id = remoteServiceClassifyOperation.saveServiceClassify(s);
			page = "service/serviceClassify.jsp";
			if (id != 0)
				return "success";
			else
				return "error";
		} catch (Exception e) {
			log.info("新增增值业务功能类别" + e.getMessage());
			return "error";
		}

	}

	/**
	 * @description 获取所有增值业务功能类别列表
	 * @author 甘雨波
	 * @date 2009-9-15 13：43
	 * @return
	 */
	@Action(value = "toDeleteServiceClassify", results = {
			@Result(name = "success", location = "/admin/service/deleteServiceClassify.jsp"),
			@Result(name = "error", location = "/admin/error.jsp") })
	public String selectAllServiceType() {
		try {
			serviceClassify = remoteServiceClassifyOperation.selectAllServiceClassify();
			//log.info("size==="+serviceClassify.size());
			return "success";
		} catch (Exception e) {
			log.info("获取增值业务功能类别列表失败" + e.getMessage());
			return "error";
		}

	}

	/**
	 * @description 删除增值业务功能类别
	 * @author 甘雨波
	 * @date 2009-9-15 13:50
	 * @return
	 */
	@Action(value = "deleteServiceClassify", results = { @Result(name = "success", location = "/admin/success.jsp"),
			@Result(name = "error", location = "/admin/error.jsp") })
	public String deleteServiceType() {
		try {
			remoteServiceClassifyOperation.deleteServiceClassify(Integer.parseInt(serviceClassifyId));
			page = "toDeleteServiceClassify";
			return "success";
		} catch (Exception e) {
			log.info("删除增值业务功能类别失败" + e.getMessage());
			return "error";
		}

	}

	/**
	 * @description 编辑增值业务功能类别
	 * @author 甘雨波
	 * @date 2009-9-14 14:00
	 * @return
	 */
	@Action(value = "updateServiceClassify", results = { @Result(name = "success", location = "/admin/success.jsp"),
			@Result(name = "error", location = "/admin/error.jsp") })
	public String updateServiceType() {
		try {
			ServiceClassify s = new ServiceClassify();
			s.setServiceClassifyId(Integer.parseInt(serviceClassifyId));
			s.setServiceClassifyName(serviceClassifyName);
			remoteServiceClassifyOperation.updateServiceClassify(s);
			page = "toDeleteServiceClassify";
			return "success";
		} catch (Exception e) {
			log.info("编辑增值业务功能类别失败" + e.getMessage());
			return "error";
		}
	}

	public String getServiceClassifyId() {
		return serviceClassifyId;
	}

	public void setServiceClassifyId(String serviceClassifyId) {
		this.serviceClassifyId = serviceClassifyId;
	}

	public String getServiceClassifyName() {
		return serviceClassifyName;
	}

	public void setServiceClassifyName(String serviceClassifyName) {
		this.serviceClassifyName = serviceClassifyName;
	}

	public List<ServiceClassify> getServiceClassify() {
		return serviceClassify;
	}

	public void setServiceClassify(List<ServiceClassify> serviceClassify) {
		this.serviceClassify = serviceClassify;
	}

	public String getPage() {
		return page;
	}

	public void setPage(String page) {
		this.page = page;
	}
}
